package cn.cuiliangpeng.org.controller;

import cn.cuiliangpeng.org.service.IShopAuditLogService;
import cn.cuiliangpeng.org.domain.ShopAuditLog;
import cn.cuiliangpeng.org.query.ShopAuditLogQuery;
import cn.cuiliangpeng.basic.utils.AjaxResult;
import cn.cuiliangpeng.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/shopAuditLog" )
public class ShopAuditLogController {

    @Autowired
    public IShopAuditLogService shopAuditLogService;

    /**
     * 接口：添加或修改
     * @param shopAuditLog 传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult updateAndAdd(@RequestBody ShopAuditLog shopAuditLog) {
        if ( shopAuditLog.getId() != null){
                shopAuditLogService.update(shopAuditLog);
        } else{
                shopAuditLogService.save(shopAuditLog);
        }
        return AjaxResult.me();
    }

    /**
    * 接口：删除
    * @param id
    * @return AjaxResult 响应给前端
    */
    @DeleteMapping(value = "/{id}" )
    public AjaxResult delete(@PathVariable("id" ) Long id) {
            shopAuditLogService.delete(id);
        return AjaxResult.me();
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return AjaxResult 响应给前端
    */
    @PatchMapping
    public AjaxResult patch(@RequestBody Long[] ids) {
            shopAuditLogService.patch(ids);
        return AjaxResult.me();
    }
    /**
    * 接口：查询单个对象
    * @param id
    */
    @GetMapping("/{id}" )
    public ShopAuditLog findById(@PathVariable("id" ) Long id) {
        return shopAuditLogService.findById(id);
    }

    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping
    public List<ShopAuditLog> findAll() {
        return shopAuditLogService.findAll();
    }


    /**
     * 接口：分页查询或高级查询
     * @param query 查询对象
     * @return PageList 分页对象
     */
    @PostMapping
    public PageList<ShopAuditLog> queryPage(@RequestBody ShopAuditLogQuery query) {
        return shopAuditLogService.queryPage(query);
    }
}
